package com.letv.app.ljodfh.ui.adapter.holder;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.letv.app.ljodfh.ui.utils.UIUtils;
import com.ruihang.generalibrary.ui.util.ViewUtils;
import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.letv.app.ljodfh.R;
import com.letv.app.ljodfh.beans.NewsItem;
import com.letv.app.ljodfh.ui.utils.GlideUtil;
import com.letv.app.ljodfh.ui.utils.SkipUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 24小时新闻条目
 * Created by Administrator on 2017/7/5.
 */

public class News24Holder extends BaseAbsHolder<NewsItem> implements View.OnClickListener {
    @BindView(R.id.item_news_divider)
    protected View divider;
    @BindView(R.id.item_news_image)
    protected CustomEXImageView img;
    @BindView(R.id.item_news_title)
    protected CustomFontTextView title;
    @BindView(R.id.item_news_date_value)
    protected CustomFontTextView date;
    @BindView(R.id.item_news_read_count)
    protected CustomFontTextView readCount;
    @BindView(R.id.item_news_mode_tag)
    protected CustomFontTextView liveTag;
    @BindView(R.id.item_news_tag)
    protected CustomFontTextView tag;
    @BindView(R.id.item_news_24_length)
    protected CustomFontTextView length;
    @BindView(R.id.item_news_24_media)
    protected ImageView media;

    private NewsItem temp;
    private String category ;

    public News24Holder(Context context, View itemView,String category) {
        super(context, itemView);
        itemView.setOnClickListener(this);
        this.category = category;
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(NewsItem t) {
        temp = t;
//        t.setReadCount(24700);
        String clickCount = UIUtils.getListNumber(t.getReadCount());
//        if (t.getItemMode() > 0) {
////            dot.setVisibility(View.GONE);
////            if (t.getItemMode() == 1) {
////                topLine.setVisibility(View.GONE);
////            } else {
////                topLine.setVisibility(View.VISIBLE);
////            }
//            divider.setVisibility(View.GONE);
//        } else {
////            if (dot.getVisibility() != View.VISIBLE) {
////                dot.setVisibility(View.VISIBLE);
////                topLine.setVisibility(View.VISIBLE);
////            }
//            divider.setVisibility(View.VISIBLE);
//        }
        if (t.isLiving()) {
            ViewUtils.setViewsGone(length, media);
            liveTag.setVisibility(View.VISIBLE);
        } else {
            liveTag.setVisibility(View.GONE);
            if (t.getDataType() > 1) {
                ViewUtils.setViewVisible(media);
                if (TextUtils.isEmpty(t.getDataMediaLength())) {
                    length.setVisibility(View.GONE);
                } else {
                    length.setVisibility(View.VISIBLE);
                    length.setText(t.getDataMediaLength());
                }
            } else {
                ViewUtils.setViewsGone(length, media);
            }
        }

//        if (t.getAfterTitleMode() > 0) {
//            if (t.getAfterTitleMode() == 1) {
////                ViewUtils.setViewsGone(dot, divider, topLine);
//                ViewUtils.setViewGone( divider);
//            } else if (t.getAfterTitleMode() == 2) {
////                ViewUtils.setViewsGone(dot, divider);
//                ViewUtils.setViewGone(divider);
//            }
//        } else {
////            ViewUtils.setViewsVisible(dot, divider, topLine);
//            ViewUtils.setViewsVisible(divider);
//        }
//        time.setText(DateUtils.getDateHourString(DateUtils.getDataDate(t)));
        date.setText(DateUtils.formatDate(DateUtils.getDataDate(t), ""));
        if (!TextUtils.isEmpty(clickCount)) {
            readCount.setText(clickCount);
            readCount.setVisibility(View.VISIBLE);
        } else {
            readCount.setVisibility(View.GONE);
        }
        title.setText(t.getDataTitle());
        tag.setText(t.getDataTag());
        GlideUtil.loadImgSmall169Def(context, t.getDataImg(), img);
        if (t.getNewsType() == 2) { //音频
            media.setImageResource(R.mipmap.icon_home_voice);
            media.setVisibility(View.VISIBLE);
        } else if (t.getNewsType() == 3) {   //视频
            media.setImageResource(R.mipmap.icon_home_play);
            media.setVisibility(View.VISIBLE);
        } else {
            media.setVisibility(View.GONE);
        }
    }

    @Override
    public void setItemMode(int mode) {
        super.setItemMode(mode);
//        if (mode == ITEMMODE_LAST) {
//            bottomLine.setVisibility(View.GONE);
//        } else {
//            bottomLine.setVisibility(View.VISIBLE);
//        }
    }

    @Override
    public void onDestory() {
        super.onDestory();
        if (itemView != null) {
            itemView.setOnClickListener(null);
        }
    }

    @Override
    public void onClick(View v) {
        if (temp == null) {
            Toast.makeText(context, "数据错误", Toast.LENGTH_SHORT).show();
            return;
        }
        SkipUtil.skipWithNewsItem(context, temp,category);
    }
}
